<?php
namespace My\Controller;

use Utuo\BackgroundController;

class GrouponOrderController extends BackgroundController {
	
	private $status = array(
		'0' => '禁用',
		'1' => '启用',
	);

	public function _initialize() {
		$this->setControllerTitle('团购订单管理');
		$this->setActionTitle(array(
			'index' => '订单列表',
			'details' => '订单详细',
			'recycle' => '回收站',
		));
		$this->setActionNav(array(
				'index',
				'recycle'
		));
	}
	
	public function indexAction() {
		$this->getLists(0);
	}
	
	public function recycleAction() {
		$this->getLists(1);
	}
	
	public function getLists( $is_deleted ) {
		$gid = I('gid', 0, 'intval');
		$page = $this->getPage();
		$pageSize = $this->getPageSize();
		$condition = array(
			'is_deleted' => $is_deleted,
		);
		$gid and $condition['groupon_id'] = $gid;
		$lists = M("GrouponOrder")->where($condition)->page($page)->limit($pageSize)->order('id desc')->select();
		$count = M("GrouponOrder")->where($condition)->count();
		$this->showPage($count, $pageSize, array('gid' => $gid));
		$this->assign("grouponOrderLists", $lists);
		$this->display();
	}
	
	public function detailsAction() {
		$id = I('id', 0, 'intval');
		$groupOrder = M("GrouponOrder")->where('id=%d', $id)->find();
		$groupOrder['goodsLists'] = M("GrouponOrderGoods")->where(array('order_id'=>$id))->select();
		$this->assign('grouponOrder', $groupOrder);
		$this->display();
	}
	
}